package basicknowledge;


import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.functions.Consumer;
import rx.Observable;
import rx.Subscriber;

/**
 * Created by Zonda on 2017/1/12.create操作符
 */
public class TestCreateOperators {

    public static void main(String[] args) {
        rxJavaCreate();
        rxJava2Create();
    }

    private static void rxJava2Create() {

        io.reactivex.Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> e) throws Exception {

            }
        }).subscribe(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) throws Exception {

            }
        });
//        io.reactivex.Observable
//                .create((ObservableOnSubscribe<Integer>) subscriber -> {
////                    try {
////                        if (!subscriber.isUnsubscribed()) {
////                            for (int i = 0; i < 5; i++) {
////                                subscriber.onNext(i);
////                            }
////                            subscriber.onCompleted();
////                        }
////                    } catch (Exception e) {
////                        subscriber.onError(e);
////                    }
//                })
//                .subscribe(integer -> {
//
//                });

    }

    private static void rxJavaCreate() {

        Observable.create(new Observable.OnSubscribe<Integer>() {
            @Override
            public void call(Subscriber<? super Integer> subscriber) {

            }
        }).subscribe(new Subscriber<Integer>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onNext(Integer integer) {

            }
        });
//        Observable
//                .create((Observable.OnSubscribe<Integer>) subscriber -> {
//                    try {
//                        if (!subscriber.isUnsubscribed()) {
//                            for (int i = 0; i < 5; i++) {
//                                subscriber.onNext(i);
//                            }
//                            subscriber.onCompleted();
//                        }
//                    } catch (Exception e) {
//                        subscriber.onError(e);
//                    }
//                })
//                .subscribe(new Subscriber<Integer>() {
//                    @Override
//                    public void onCompleted() {
//                        System.out.println("stream is completed !");
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        System.out.println("stream is error: " + e.getMessage());
//                    }
//
//                    @Override
//                    public void onNext(Integer integer) {
//                        System.out.println("stream is next: " + integer);
//                    }
//                });
    }
}
